package com.chpro.http.yixin.receive;

import com.chpro.common.JSONUtils;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;

/**
 * Created by Administrator on 14-10-3.
 */
@XStreamAlias("xml")
public class MsgModel {
    @XStreamAlias("ToUserName")
    private String toUserName;
    @XStreamAlias("FromUserName")
    private String fromUserName;
    @XStreamAlias("CreateTime")
    private String createTime;
    @XStreamAlias("MsgId")
    private String msgId;
    @XStreamAlias("MsgType")
    private String msgType; //文本消息:text   图片消息:image  语音消息:audio 视频:video

    @XStreamAlias("Content")
    private String content; //文本消息特有节点

    @XStreamAlias("Event")
    private String event;   //事件消息特有内容  CLICK

    @XStreamAlias("EventKey")
    private String eventKey;    //自定义菜单事件:与自定义菜单接口中KEY值对应; 扫描带参数二维码事件:qrscene_为前缀，后面为二维码的参数值

    @XStreamAlias("ticket")
    private String Ticket;  //二维码的ticket，可用来换取二维码图片

    @XStreamAlias("Url")
    private String url; //音频地址。

    @XStreamAlias("name")
    private String name;    //音频文件名称

    @XStreamAlias("mimeType")
    private String mimeType;    //音频格式

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getEventKey() {
        return eventKey;
    }

    public void setEventKey(String eventKey) {
        this.eventKey = eventKey;
    }

    public String getTicket() {
        return Ticket;
    }

    public void setTicket(String ticket) {
        Ticket = ticket;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public static MsgModel toObject(String content){
        XStream xstream = new XStream();
        xstream.processAnnotations(MsgModel.class);
        return (MsgModel)xstream.fromXML(content);
    }

    public static void main(String[] args){
        //易信普通文本消息
        String txtMsg = "<xml>\n" +
                "  <ToUserName><![CDATA[058615fa9a96c7c8c3061cd18d77b7a0]]></ToUserName>\n" +
                "  <FromUserName><![CDATA[1887c2b4c2436419c3061cd18d77b7a0]]></FromUserName>\n" +
                "  <CreateTime>1411868845</CreateTime>\n" +
                "  <MsgId>20</MsgId>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                //"  <Content><![CDATA[147]]></Content>\n" +  //文件消息特有内容
                "  <Event><![CDATA[subscribe]]></Event>\n"+
                "</xml>";
        MsgModel msgModel = new MsgModel();
        msgModel = msgModel.toObject(txtMsg);
        System.out.println(JSONUtils.toJSON(msgModel));
    }
}
